package com.primeton.wh.mcenter.impl.message.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.primeton.wh.mcenter.api.model.Application;
import com.primeton.wh.mcenter.impl.message.mapper.ApplicationMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2020-03-19 16:53
 * @description:
 **/
@Component
public class ApplicationDAO {

    @Resource
    private ApplicationMapper applicationMapper;


    /**
     * 分页查询DAO方法
     *
     * @param condition :
     * @return : com.baomidou.mybatisplus.core.metadata.IPage<com.primeton.wh.mcenter.impl.message.entity.Application>
     * @author : YunTao.Li
     * @date : 2020/3/19 2020/3/19
     */
    public IPage<Application> getApplicationList(Map<String, Object> condition) throws Throwable {
        Long currentPage = (Long) condition.get("page");
        Long currentPageSize = (Long) condition.get("limit");


        IPage<Application> page = new Page(currentPage, currentPageSize);

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("APP_SORT");

        IPage<Application> applicationIPage = applicationMapper.selectPage(page, queryWrapper);

        return applicationIPage;
    }

    /**
     * 将Application对象插入数据库
     *
     * @param record :
     * @return : void
     * @author : YunTao.Li
     * @date : 2020/3/16 2020/3/16
     */
    public void insertApplication(Application record) throws Throwable {
        applicationMapper.insert(record);
    }

    /**
     * 修改Application
     *
     * @param record :
     * @return : void
     * @author : YunTao.Li
     * @date : 2020/3/19 2020/3/19
     */
    public void updateApplication(Application record) {
        applicationMapper.updateById(record);
    }
}
